// components/com/com.js
const myBehavior = require('../my-behavior')
const app = getApp()
let plugin = requirePlugin('routePlan');
console.log(app)
app.globalData.userid = 1111
console.log(app)
Component({
  behaviors: [myBehavior], // vue  mixins: [myMixins]
  options: {
    multipleSlots: true // 在组件定义时的选项中启用多slot支持
  },
  /**
   * 组件的属性列表   vue中的props
   */
  properties: {
    name: String,
    age: Number
  },

  /**
   * 组件的初始数据
   */
  data: {
    msg: 'hello minipro',
    firstName: '',
    lastName: '',
    fullName: ''
  },

  /**
   * 组件的方法列表
   */
  methods: {
    clickHandler (event) {
      console.log('点击事件', event)
    },
    clickHandlerParams (event) {
      console.log(event.target.dataset.str)
    },
    reverseMsg () {
      this.setData({
        msg: this.data.msg.split('').reverse().join('')
      })
    },
    addCount () {
      this.setData({
        count: this.data.count + 1
      })
    },
    changeFirstName (event) {
      this.setData({
        firstName: event.detail.value
      })
    },
    changeLastName(event) {
      console.log(event)
      this.setData({
        lastName: event.detail.value
      })
    },
    testOrc () {
      wx.chooseImage({
        count: 1,
        success: async function(res) {
          try {
            const invokeRes = await wx.serviceMarket.invokeService({
              service: 'wx79ac3de8be320b71',
              api: 'OcrAllInOne',
              data: {
                // 用 CDN 方法标记要上传并转换成 HTTP URL 的文件
                img_url: new wx.serviceMarket.CDN({
                  type: 'filePath',
                  filePath: res.tempFilePaths[0],
                }),
                data_type: 3,
                ocr_type: 1
              },
            })
      
            console.log('invokeService success', invokeRes)
            wx.showModal({
              title: 'success',
              content: JSON.stringify(invokeRes),
            })
          } catch (err) {
            console.error('invokeService fail', err)
            wx.showModal({
              title: 'fail',
              content: err,
            })
          }
        },
        fail: function(res) {},
        complete: function(res) {},
      })
    },
    addressTest () {
      let key = '736BZ-SYKNJ-JDZF2-FGJUL-7TKTE-BPFGA';  //使用在腾讯位置服务申请的key
let referer = 'sz2107';   //调用插件的app的名称
let endPoint = JSON.stringify({  //终点
  'name': '北京西站',
  'latitude': 39.894806,
  'longitude': 116.321592
});
wx.navigateTo({
  url: 'plugin://routePlan/index?key=' + key + '&referer=' + referer + '&endPoint=' + endPoint
});
    }
    
  },
  observers: {
    count (val) {
      console.log(val)
    },
    "firstName, lastName": function (firstName, lastName) {
      this.setData({
        fullName: firstName + lastName
      })
    },
    "**": function (val) {
      console.log('val', val)
    }
  }
})
